package com.siwei.mes.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.ExperimentQuickRecord;
import com.siwei.mes.mapper.ExperimentQuickRecordMapper;
import com.siwei.mes.service.ExperimentQuickRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 试验台账快检信息(ExperimentQuickRecord)表服务实现类
 *
 * @author linzi
 * @since 2023-12-24 21:44:10
 */
@Service
public class ExperimentQuickRecordServiceImpl implements ExperimentQuickRecordService {
    @Resource
    private ExperimentQuickRecordMapper experimentQuickRecordMapper;

    @Override
    public Long create(ExperimentQuickRecord entity) {
        experimentQuickRecordMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(ExperimentQuickRecord entity) {
        ExperimentQuickRecord experimentQuickRecord = experimentQuickRecordMapper.selectByPrimaryKey(entity.getId());
        assertTrue(experimentQuickRecord == null, "试验台账快检信息信息不存在");
        experimentQuickRecordMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        ExperimentQuickRecord experimentQuickRecord = experimentQuickRecordMapper.selectByPrimaryKey(id);
        assertTrue(experimentQuickRecord == null, "试验台账快检信息信息不存在");
        experimentQuickRecordMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<ExperimentQuickRecord> getPage(PageQuery<ExperimentQuickRecord, ExperimentQuickRecord> query) {
        ExperimentQuickRecord searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> experimentQuickRecordMapper.getList(searchParam));
    }

    @Override
    public ExperimentQuickRecord loadById(Long id) {
        return experimentQuickRecordMapper.loadById(id);
    }

    @Override
    public List<ExperimentQuickRecord> getAll(ExperimentQuickRecord entity) {
        return experimentQuickRecordMapper.getList(entity);
    }
}
